package vaccine.appointment.system.common.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

/**
 * 身份证号验证器（简化：只校验 18 位数字）
 */
public class IdCardValidator implements ConstraintValidator<IdCard, String> {
    
    private static final Pattern SIMPLE_PATTERN = Pattern.compile("^\\d{18}$");
    
    @Override
    public void initialize(IdCard constraintAnnotation) {
        // 初始化方法
    }
    
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null || value.isEmpty()) {
            return true;
        }
        return SIMPLE_PATTERN.matcher(value).matches();
    }
}

